package org.example.clouddemo.order;

import lombok.Getter;

// 定义业务状态枚举
@Getter
public enum OrderStatus {

    CREATED(0, "已创建"),
    PAID(1, "已支付"),
    CANCELED(2, "已取消"),
    //产品库存不够
    INSUFFICIENT_STOCK(3, "库存不足结算失败"),
    //用户余额不足
    INSUFFICIENT_BALANCE(4, "余额不足结算失败"),
    //"用户ID为空" 创建订单失败
    USER_ID_EMPTY(5, "用户ID为空"),
    //"商品ID为空" 创建订单失败
    PRODUCT_ID_EMPTY(6, "商品ID为空"),
    //购买数量《=0 创建订单失败"
    QUANTITY_INVALID(7, "购买数量<=0 创建订单失败"),
    //"商品不存在" 创建订单失败
    PRODUCT_NOT_EXIST(8, "商品不存在"),
    //"用户不存在" 创建订单失败
    USER_NOT_EXIST(9, "用户不存在"),
    //没有admin权限
    NO_ADMIN_ROLE(10,"没有admin权限"),
    //查询结果为空
    RESULT_EMPTY(11,"查询结果为空"),
    //数据库操作失败
    ORDER_FAILED(12,"数据库操作失败"),
    //数据库操作成功
    ORDER_SUCCESS(13,"数据库操作成功"),
    //业务完成
    COMPLETED (14,"业务完成"),
    //业务失败
    FAILED (15,"业务失败"),
    //订单状态描述
    //订单无法修改
    CANNOT_MODIFY(16,"订单无法修改"),
    //订单无法删除
    CANNOT_DELETE(17,"订单无法删除"),
    //订单无法修改数量
    CANNOT_UPDATE_QUANTITY(18,"订单无法修改数量"),
    //订单无法结算
    CANNOT_SETTLE(19,"订单无法结算");


    private final int code;
    private final String desc;
    
    OrderStatus(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    // 根据代码获取枚举
    public static OrderStatus getByCode(int code) {
        for (OrderStatus status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("未知订单状态码: " + code);
    }
}